package com.yufubao.api.controller.applet.product;


import com.yufubao.framework.annotation.AutAccess;
import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.result.PageUtils;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.pojo.applet.product.SupplierProductCategoryEntity;
import com.yufubao.service.service.applet.product.SupplierProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 产品分类表
 *
 * @author zhangzhan
 * @email 52194440@qq.com
 * @date 2024-08-26 21:31:25
 */
@Api("applet产品分类")
@RestController
@RequestMapping("/applet/supplierproductcategory")
public class SupplierProductCategoryController {
    @Autowired
    private SupplierProductCategoryService supplierProductCategoryService;

    /**
     * applet产品分类树化
     */
    @SystemLog(info = "applet产品分类树化")
    @RequestMapping(value = "/listTree",method = RequestMethod.GET)
    @ApiOperation(value = "applet产品分类树化")
    @AutAccess
    public ResponseResult listTree(){
        return supplierProductCategoryService.listTree();
    }


    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ApiOperation(value = "列表")
    public ResponseResult list(@RequestBody Map<String, Object> params){
        PageUtils page = supplierProductCategoryService.queryPage(params);

        return ResponseResult.okResultPage("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{categoryId}",method = RequestMethod.GET)
    @ApiOperation(value = "信息")
    public ResponseResult info(@PathVariable("categoryId") Integer categoryId){
		SupplierProductCategoryEntity supplierProductCategory = supplierProductCategoryService.getById(categoryId);

        return ResponseResult.okResultPage("SupplierProductCategory", supplierProductCategory);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "保存")
    public ResponseResult save(@RequestBody SupplierProductCategoryEntity supplierProductCategory){
		supplierProductCategoryService.save(supplierProductCategory);

        return ResponseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @ApiOperation(value = "修改")
    public ResponseResult update(@RequestBody SupplierProductCategoryEntity supplierProductCategory){
		supplierProductCategoryService.updateById(supplierProductCategory);

        return ResponseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @ApiOperation(value = "删除")
    public ResponseResult delete(@RequestBody Integer[] categoryIds){
		supplierProductCategoryService.removeByIds(Arrays.asList(categoryIds));

        return ResponseResult.ok();
    }

}
